#!/usr/bin/env python
# -*- coding:utf-8 -*-
#/home/zc/workspace/tinyfeet/trunk/src/controllers/feedback.py
'''
用户反馈接口

Created on 2012-4-1

@author: zc
'''

import web
import simplejson
from dbhandle.mysqldb import mysqldb 
from datetime import datetime
from checkkey import checkkey


class feedback( object ):
    '''  接收反馈信息并存储到DB    '''
    def POST( self ):
        data = web.input()
        if checkkey( web.config._session, web.ctx.env ):
            addres = self.addfeed( data )
        else:
            addres = '{"msg":"203", "errmsg":"session验证未通过."}' 
        return addres


    def addfeed( self, feedBody ):
        """ 增加评论 
        {
            "uid":1223,
            "feedback":"发tfeet怎么老失败啊",
            }
         """
        #json_data = simplejson.loads( cmtsBody )
        uid = feedBody.uid
        feedback = feedBody.feedback
        cdate = datetime.now().strftime( "%Y%m%d%H%M%S" )
        dbo = mysqldb()
        row = dbo.insert( 'feedback', uid = uid, feedback = feedback, feedback_date = cdate )
        if row <> -1:
                res = '{"msg":"200"}'  
        else:
                res = '{"msg":"202", "errmsg":"提交feedback失败."}'
        
        return res
